package cn.wzy.controller;

import cn.wzy.annotation.AnPermission;
import cn.wzy.pojo.Department;
import cn.wzy.results.ResponseResult;
import cn.wzy.service.DepartmentService;
import cn.wzy.vo.GoPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TDepartment)表控制层
 *
 * @author makejava
 * @since 2022-12-08 13:53:14
 */
@RestController
@RequestMapping("/department")
@Api(value = "部门操作",tags = "部门")
@AnPermission(name = "部门管理",descs = "对部门资源的管理")
public class DepartmentController {
    /**
     * 服务对象
     */
    @Resource
    private DepartmentService departmentService;

    /*
    * 查询分页
    * */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询",tags = "分页")
    @AnPermission(name = "部门分页高级查询")
    public ResponseResult getDepartmentsPage(@RequestBody GoPageVo goPageVo){
        return departmentService.getDepartmentsPage(goPageVo);
    }

    /*
    * 查询
    * */
    @GetMapping("/{id}")
    @AnPermission(name = "部门id查询")
    @ApiOperation(value = "查询部门",tags = "懒查询")
    public ResponseResult getDepartments(@PathVariable("id") Long id){
        return departmentService.getDepartments(id);
    }

    /*
    * 新增和修改
    * */
    @PostMapping
    @AnPermission(name = "部门修改或者添加")
    @ApiOperation(value = "新增或者修改",tags = "新增或者修改")
    public ResponseResult saveDepartment(@RequestBody Department department){
        return departmentService.saveDepartment(department);
    }

    /*
    * 删除部门
    * */
    @DeleteMapping("/{id}")
    @AnPermission(name = "部门id删除")
    @ApiOperation(value = "删除部门",tags = "删除部门")
    public ResponseResult deleteDepartment(@PathVariable("id") Long id){
        return departmentService.deleteDepartment(id);
    }


    /*
    * 批量删除部门
    * */
    @PatchMapping
    @AnPermission(name = "部门批量删除")
    @ApiOperation(value = "批量删除部门",tags = "批量删除部门")
    public ResponseResult deleteDepartmentList(@RequestBody List<Long> ids){
        return departmentService.deleteDepartmentList(ids);
    }

    /*
    * 查询多级部门
    * */
    @GetMapping
    @AnPermission(name = "部门多级查询")
    @ApiOperation(value = "多级部门")
    public ResponseResult getDepLevel(){
        return departmentService.getDepLevel();
    }

    /*
    * 查询多级三级部门
    * */
    @GetMapping("/threeLevel")
    @AnPermission(name = "三层部门查询")
    @ApiOperation(value = "三级部门")
    public ResponseResult getDepThreeLevel(){
        return departmentService.getDepThreeLevel();
    }
}

